Skip to content

Auto-detect function argument types when dropping or updating#203

Draft
teoljungberg wants to merge 10 commits into
masterfrom
auto-detect-function-arguments
Draft

Auto-detect function argument types when dropping or updating#203
teoljungberg wants to merge 10 commits into
masterfrom
auto-detect-function-arguments

Conversation

@teoljungberg

@teoljungberg teoljungberg commented Mar 1, 2026

Copy link
Copy Markdown
Owner

Functions with parameters could not be dropped or updated
because PostgreSQL requires argument types in DROP FUNCTION.
This has been the longest-standing open issue (#7, 2017).

  • Look up argument types from pg_proc automatically at
    drop/update time
  • Accept an explicit arguments: option on drop_function and
    update_function for overloaded functions
  • Raise Fx::AmbiguousFunctionError with guidance when multiple
    overloads exist and no arguments: option is given
  • Forward arguments: through Fx::Statements using
    **options.slice(:arguments), keeping custom adapters working

Closes #7

@teoljungberg teoljungberg force-pushed the auto-detect-function-arguments branch from e035865 to e47e07c Compare March 1, 2026 08:01
@teoljungberg teoljungberg changed the base branch from housekeeping to master March 7, 2026 10:50
@teoljungberg teoljungberg force-pushed the auto-detect-function-arguments branch from e47e07c to a94c6c2 Compare March 7, 2026 10:51
teoljungberg added a commit that referenced this pull request Mar 8, 2026
- Fetch `pg_get_function_identity_arguments` in the schema dump query so
each `Fx::Function` knows its argument types
- Add `Function#signature` returning the full PostgreSQL identity (e.g.
`add(integer, integer)` or `now_utc()`)
- Use `signature` for `==` and `<=>` so overloaded functions with the
same name but different arguments are correctly distinguished
- `arguments` is kept private; `signature` is the public API

Foundational change that both #203 and the dependency sorting PR can
build on.
@teoljungberg teoljungberg force-pushed the auto-detect-function-arguments branch from 5675428 to 297eb3d Compare March 8, 2026 08:34
@teoljungberg teoljungberg marked this pull request as draft March 8, 2026 09:19
Functions with parameters previously could not be dropped or updated
because PostgreSQL requires the argument types in DROP FUNCTION for
functions that accept arguments. The adapter now looks up argument types
from pg_proc automatically, removing the need for manual intervention.

For overloaded functions (same name, different signatures), an explicit
`arguments:` option is available on drop_function and update_function to
disambiguate. When multiple overloads exist and no arguments are given,
an AmbiguousFunctionError is raised with guidance.

Closes #7
- Use .presence on pg_get_function_identity_arguments result so no-arg
  functions preserve the original DROP FUNCTION name form instead of
  generating unnecessary empty parens
- Handle quoted identifiers in schema-qualified names (e.g.
  "My_Schema"."My_Func") by parsing with a regex instead of split
- Document that the arguments: option is Postgres-specific and that
  custom adapters must accept the keyword to use it
Replace manual signature string construction with
Function#signature in drop_function and the ambiguous
function error message.
Replace the separate FUNCTION_ARGUMENTS_QUERY with a lookup
against the existing functions method, which already fetches
arguments via pg_get_function_identity_arguments.
The command recorder passes arguments through when reverting
drop_function, so create_function must accept it even though
it is unused during creation.
@teoljungberg teoljungberg force-pushed the auto-detect-function-arguments branch from 50e05ae to 7bc3c52 Compare April 5, 2026 17:36
@carter-thaxton

Copy link
Copy Markdown

This looks great. I like that it handles the unambiguous case automatically, and provides a straightforward way to handle overloads.

What will it take to get this into the released version of the gem? I'd love to start using it right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't use function with parameters

2 participants